
CREATE PROC SP_CREATE_UPDATE_DIEBANK_RECEIVE_LOT_BIN_INFO 
(
 @PROCESS_STEP_ID 	INT,	
 @VENDOR_NAME 		VARCHAR(50),
 @LOT_NUMBER 		VARCHAR(50),
 @WAFER_ID			VARCHAR(10),
 @BIN_QTY			INT, 
 @PROCESS_TYPE      VARCHAR(50),
 @LOT_ID		    INT
 )
 AS
 BEGIN

  	DECLARE @LOCATION_ID INT
 	DECLARE @DIE_BANK_LOT_ID INT

	SELECT @LOCATION_ID = LOCATION_ID FROM LOCATION WHERE L_TYPE = 'DIE BANK' AND L_VENDOR_NAME = @VENDOR_NAME
 	
 	SELECT @DIE_BANK_LOT_ID = LOT_ID FROM LOT_TABLE WHERE PROCESSSTEP_ID = @PROCESS_STEP_ID AND LOCATION_ID = @LOCATION_ID AND LOT_NUMBER = @LOT_NUMBER

	/*inserting in to sort bin release table*/
	IF @DIE_BANK_LOT_ID IS NOT NULL
	BEGIN
		EXEC SP_SAVE_INFORMATIVE_BINNING_INFO @DIE_BANK_LOT_ID, @WAFER_ID, 'Bin1', @BIN_QTY, 0/*rejectedqty*/, 0.0/*yield*/
	END
	
	IF @PROCESS_TYPE = 'DIE BANK'
	BEGIN
			UPDATE SORT_BIN_RELEASE_TABLE SET BIN_1_TRANSIT_QTY = BIN_1_TRANSIT_QTY - @BIN_QTY WHERE LOT_ID = @LOT_ID AND WAFER_ID = @WAFER_ID			
	END
END
